package com.timesheet.server.core.mapper;

import java.lang.reflect.Field;

public class Mapper<T> {

	public T map(T a1, Object b1) throws IllegalArgumentException,
			IllegalAccessException {

		Class<? extends Object> a = a1.getClass();

		Class<? extends Object> b = b1.getClass();

		Field[] declaredFields = a.getDeclaredFields();
		Field[] declaredFields2 = b.getDeclaredFields();

		for (int i = 0; i < declaredFields2.length; i++) {

			Field field1 = declaredFields[i];
			field1.setAccessible(true);

			Field field2 = declaredFields2[i];
			field2.setAccessible(true);

			for (Field field : declaredFields) {

				if (field.getName().equals(field2.getName())
						&& !field.getName().equals("serialVersionUID")) {

					Object object = field2.get(b1);
					field1.set(a1, object);
				}
			}
		}

		return a1;

	}

}
